var t = require("../../../@babel/runtime/helpers/defineProperty"), n = getApp();

Page({
    data: {
        pass: !1,
        question: [],
        answer: [],
        score: "",
        is_qualified: ""
    },
    onLoad: function(t) {
        this.init(), this.getData();
    },
    init: function() {
        this.setData({
            question: [],
            answer: [],
            score: [],
            is_qualified: "",
            pass: !1
        });
    },
    again: function() {
        this.init(), wx.pageScrollTo({
            duration: 1e3,
            scrollTop: 0
        }), this.getData();
    },
    onClose: function() {
        this.setData({
            pass: !1
        });
    },
    goApply: function() {
        wx.navigateTo({
            url: "/packageE/video_question/apply/apply"
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getData: function() {
        var t = this, a = n.getNetAddresss("plugin.agent-qa.api.answer-question.get-question");
        n._postNetWork({
            url: a,
            success: function(n) {
                var a = n.data;
                1 == a.result ? t.setData({
                    question: a.data
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: t.msg,
                    icon: "none"
                });
            }
        });
    },
    tapAnswer: function(n) {
        console.log(n);
        var a = n.currentTarget.dataset.qid, e = n.currentTarget.dataset.aid, s = {}, o = this.data.answer;
        if (s.question_id = a, s.answer_id = e, 0 == this.data.answer.length) o[0] = s; else {
            var i = this.check(o, a);
            console.log(i), i || 0 == i ? o[i] = s : o[o.length] = s;
        }
        for (var r = this.data.question, c = 0; c < r.length; c++) if (r[c].id == a) for (var u = 0; u < r[c].option.length; u++) r[c].option[u].id == e ? (console.log("111111111111111111"), 
        this.setData(t({}, "question[".concat(c, "].option[").concat(u, "].crd"), !0))) : this.setData(t({}, "question[".concat(c, "].option[").concat(u, "].crd"), !1));
        this.setData({
            answer: o,
            question: r
        });
    },
    check: function(t, n) {
        for (var a = 0; a < t.length; a++) if (t[a].question_id == n) return console.log("1q2", a), 
        a;
    },
    submit: function() {
        var t = this, a = JSON.stringify(t.data.answer), e = n.getNetAddresss("plugin.agent-qa.api.answer-question.answer-question");
        n._postNetWork({
            url: e,
            data: {
                answers: a
            },
            success: function(n) {
                var a = n.data;
                1 == a.result && t.setData({
                    pass: !0,
                    is_qualified: a.data.is_qualified,
                    score: a.data.score
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: t.msg,
                    icon: "none"
                });
            }
        });
    }
});